package homework.api.day02;

import java.util.Arrays;

public class StringRegexDemo {
    public static void main(String[] args) {
        //验证字符串的格式matches
        //验证邮箱格式
        String email = "sdhkfjsjdf@fhd.cmo.ccn";
        String regex = "\\w+@[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";
        boolean flag = email.matches(regex);
        System.out.println("验证结果："+flag);

        //替换符合正则的字符串部分为参数中的字符串replaceAll
        //替换a-c为$AC$
        String line = "aaa741adccfrghba963";
        line = line.replaceAll("[a-c]+","\\$AC\\$");
        System.out.println(line);

        //将字符串按照符合正则的字符串进行拆分，拆为数组split
        //若末尾拆分出一堆""的元素，则会舍弃
        line = ".00.45.4874......";
        String[] arr =line.split("\\.");
        System.out.println(Arrays.toString(arr));

    }
}
